package com.rockcent.wechat.helper;

import com.rockcent.mall.lib.domain.ChannelEvent;
import com.rockcent.mall.lib.dto.ChannelEventDto;
import com.rockcent.mall.lib.helper.BaseChannelHelper;
import com.rockcent.mall.lib.repository.ChannelEventRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;

/**
 * Created by zhangjh on 2016/10/9.
 */
@Component
public class ChannelHelper extends BaseChannelHelper{
    private static final Logger log = LoggerFactory.getLogger(ChannelHelper.class);

    @Autowired
    private ExecutorService commonExecutorService;
    @Autowired
    private ChannelEventRepository channelEventRepository;

    /**
     * 保存渠道访问数
     * @param channelEventDto
     */
    public void addChannelViewLog(ChannelEventDto channelEventDto) {
        // 异步任务
        commonExecutorService.execute(() -> {
            ChannelEvent channelEvent = new ChannelEvent();
            channelEvent.setChannelId(channelEventDto.getChannelId());
            channelEvent.setMallId(channelEventDto.getMallId());
            channelEvent.setMerchantId(channelEventDto.getMerchantId());
            channelEvent.setVisitIp(channelEventDto.getVisitIp());
            channelEvent.setVisitCustomerId(channelEventDto.getVisitCustomerId());
            channelEventRepository.save(channelEvent);
        });
    }
}
